# -*- coding: utf-8 -*-

import serial
from mavlinkParser import *
import random
import time

baudrate = 115200
port =  'COM2'
device = serial.Serial(port,baudrate=baudrate)
while True:
    length = random.randint(30,40)
    leng   = chr(length)
    seq    = chr(random.randint(1,40))
    sysid  = chr(random.randint(1,10))
    compid = chr(random.randint(2,100))
    msgid  = chr(random.randint(1,5))
    payload = ''
    # length = length + random.randint(0,10)/8
    for i in range(0,length):
        payload = payload + chr(random.randint(0,127))

    crcStream = leng  + seq  + sysid  + compid + msgid  + payload
    crc  = crc_calculate(crcStream,ord(msgid))
    msg = 'fe'.decode('hex')+crcStream+crc
    # length = random.randint(0,10)/9
    length = 0
    for i in range(0,length):
        msg = msg + chr(random.randint(0,127))
    device.write(msg)
    time.sleep(0.05)